$(document).ready(function () {
	sfxycx.onLoad();
})

var sfxycx = (function () {
	var init = function () {
		//私有属性
		var curSeg;
		layui.use('form', function(){
		  var form = layui.form
		});
		layui.use('layer', function () {
			var layer = layui.layer;
		});
		$('#picCode').attr("src", 'https://wsbsfwt.ha-n-tax.gov.cn/cm/showPictureCode.do?t=' + Math.random());
	}
	return {
		onLoad: function () {
			init();
			sfxycx.reloadPicCode()
		},
		/*查询*/
		onQuery: function () {
			var sfxyh = $(".sfxyh").val().trim();
			var rcode=$(".rcode").val();
			if (sfxyh != "" && rcode != "") {
				$.ajax({
					url: "https://wsbsfwt.ha-n-tax.gov.cn/taxclient/wssq/sbzs/checkSfxy.do?",
					type: "GET",
					data: {
						SFXYH:sfxyh,
						rcode:rcode
					},
					dataType: "jsonp",
					jsonpCallback: "sfxycx.onqueryCallback",
				});
			} else if(sfxyh==""){
				layui.use('layer', function () {
					var layer = layui.layer;
					layer.msg('三方协议号不能为空');
				});
			}else if(rcode==""){
				layui.use('layer', function () {
					var layer = layui.layer;
					layer.msg('验证码不能为空');
				});
			}
		},
		
		onqueryCallback: function (jsonObj) {
			sfxycx.reloadPicCode();
			$(".rcode").val("");
			if(jsonObj.data ){
            	$("#wxlSfxycx tbody tr td:last-child").each(function(){
            		var namVal=$(this).attr("name");
            		if(namVal=="SFXYZT_DM"){
            			if(jsonObj.data[namVal]=="01"){
            				$(this).html("未验证");
            			}else if(jsonObj.data[namVal]=="02"){
            				$(this).html("验证通过");
            			}else if(jsonObj.data[namVal]=="03"){
            				$(this).html("验证失败");
            			}else if(jsonObj.data[namVal]=="04"){
            				$(this).html("协议终止");
            			}
            		}else{
            			$(this).html(jsonObj.data[namVal]);
            		}
            	});
			}else{
				$("#wxlSfxycx tbody tr td:last-child").empty();
				
				layer.msg(jsonObj.msg)
			}
		},
		winReset: function () {
			var nsrsbh = $(".wxl_cxSearch input").val("");
			$("#wxlSfxycx tbody tr td:last-child").empty();
			sfxycx.reloadPicCode();
		},
		//验证码
        reloadPicCode: function () {
            // http://jcpt.ha-n-tax.gov.cn
            $('#picCode').attr("src", 'https://wsbsfwt.ha-n-tax.gov.cn/cm/showPictureCode.do?t=' + Math.random());
        }
	}
})();
